{% extends 'front/base.html' %}
{% block css %}
    <link rel="stylesheet"
          href="{{ url_for('static', filename='css/pure-min.css') }}">
    <link rel="stylesheet"
          href="{{ url_for('static', filename='css/create.css') }}">
{% endblock %}
{% block content %}
    <div class="form_box">
        <h3 class="club-access-header" style="margin-bottom: 20px">您正在访问: <span>{{ club.name}}</span></h3>
        <form class="pure-form pure-form-aligned pure-u-1 pure-u-md-21-24" method="post" action="">
            {{ form.csrf_token }}
            <input type="text" value="{{ club.id }}" name="club_id" style="display: none" id="club_id" />
            <div class="pure-control-group">
{#                <label class="pure-u-2-5" for="">访问密码</label>#}
                {{ form.password(class='pure-u-5-5',placeholder='请输入访问密码', required='') }}
            </div>
            <div class="pure-control-group" style="text-align: right">
                <button type="submit" class="button-warning pure-button button-large pure-u-1-6"  formaction="s1.jsp" formmethod="post">保存密码访问</button>
                <button type="submit" class="button-success pure-button button-large pure-u-1-6">访问</button>
{#                <label class="pure-u-1-6"></label>#}
            </div>
        </form>
  </div>
{% endblock %}
{% block scripts %}
{#    {{ super() }}#}
    <script>
        function showBox(club_id){
            console.log(club_id)
            let request_html = jQuery("#access-box").html()
            let re = new RegExp("to-be-replace","g"); //定义正则表达式
            let ret = new RegExp("form-old","g"); //定义正则表达式
            let rete = new RegExp("mod-go-access","g"); //定义正则表达式
            //第一个参数是要替换掉的内容，第二个参数"g"表示替换全部（global）。
            let NewStr = request_html.replace(re, club_id.toString()); //第一个参数是正则表达式。
            let newString = NewStr.replace(ret, "form"); //第一个参数是正则表达式。
            let new_string = newString.replace(rete, "go-access"); //第一个参数是正则表达式。
            console.log(new_string)
            layer.open({
              type: 1, title: '输入访问密码',
              skin: 'layui-layer-demo', //样式类名
              closeBtn: 1, //不显示关闭按钮
              anim: 2,
              shadeClose: true, //开启遮罩关闭
              content: new_string
            });
        }
        jQuery("#go-access").on("click", function (){
            console.log($('#form').serialize())
            $.ajax({
            type: "post",   //请求类型
            dataType: "json",   //请求数据返回类型
            url: "/admin/json_data/sent_data",    //请求地址
            data: $('#form').serialize(),       //表单序列化
            success: function (result) {        //成功
                console.log(result);
                if (result.code === 200) {
                    console.log(result);
                    console.log("成功");
                    {#$("#club_id").text(result.data.name);#}
                    {#$("#password").text(result.data.phone);#}
                } else {
                    console.log(result);
                    console.log("失败");
                }
            },
            error: function (result) {      //失败
                console.log(result);
                console.log("异常");
            }
        });
        return false;
        })
    </script>
{% endblock %}